using MicroMsg.UI.Page;
using Microsoft.Phone.Controls;
using Microsoft.Xna.Framework.Media;
using System;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class ChooserImage : UserControl
	{
		public Picture mPicture;
		internal Button LayoutItem;
		internal Image image;
		internal Image imgSelected;
		private bool _contentLoaded;
		public ChooserImage()
		{
			this.InitializeComponent();
			base.SetValue(TiltEffect.IsTiltEnabledProperty, true);
			this.LayoutItem.set_DataContext(this);
		}
		public void SetPicture(Picture picture)
		{
			this.mPicture = picture;
			try
			{
				if (picture != null)
				{
					base.set_Tag(picture);
					base.set_Visibility(0);
					BitmapImage bitmapImage = new BitmapImage();
					Stream thumbnail = picture.GetThumbnail();
					if (thumbnail == null)
					{
						base.set_Visibility(1);
					}
					else
					{
						bitmapImage.SetSource(thumbnail);
						this.image.set_Source(bitmapImage);
					}
					bool flag = MultiPhotoChooser.sSelectedPictures.Contains(this.mPicture);
					this.SetSelected(flag);
					MultiPhotoChooser.HandlePicViewsMap(picture, flag, this);
				}
				else
				{
					base.set_Visibility(1);
				}
			}
			catch (Exception)
			{
				base.set_Visibility(1);
			}
		}
		public void SetSelected(bool isSelected)
		{
			if (isSelected)
			{
				this.imgSelected.set_Visibility(0);
				return;
			}
			this.imgSelected.set_Visibility(1);
		}
		private void btnLayoutRoot_Click(object sender, RoutedEventArgs e)
		{
			MultiPhotoChooser currentPage = MultiPhotoChooser.GetCurrentPage();
			if (currentPage == null)
			{
				return;
			}
			if (MultiPhotoChooser.sSelectedPictures.Contains(this.mPicture))
			{
				if (currentPage.SetSelectState(this.mPicture, false, this))
				{
					this.SetSelected(false);
					return;
				}
			}
			else
			{
				if (currentPage.SetSelectState(this.mPicture, true, this))
				{
					this.SetSelected(true);
				}
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Util/MultiPhotoChooser/ChooserImage.xaml", 2));
			this.LayoutItem = (Button)base.FindName("LayoutItem");
			this.image = (Image)base.FindName("image");
			this.imgSelected = (Image)base.FindName("imgSelected");
		}
	}
}
